package com.sos.logging
{
	
	import flash.utils.Dictionary;

	/**
	 * 
	 * @author luca tavecchia
	 * 
	 */	
	public class LogTargetFactory
	{
		
		// -------------------------------------------------------------------------------
		// FIELDS
		// -------------------------------------------------------------------------------
		
		private static var _targets:Dictionary = new Dictionary(true);
		
		// -------------------------------------------------------------------------------
		// PRIVATE METHODS
		// -------------------------------------------------------------------------------
		
		private static function getTargetInstance(targetType:LogTargetType):LogTarget
		{
			return _targets[targetType];
		}
		
		// -------------------------------------------------------------------------------
		// PUBLIC METHODS
		// -------------------------------------------------------------------------------
		
		public static function getInstance(targetType:LogTargetType, options:LogTargetParams = null):LogTarget
		{
			// Search if the target instance already exists
			var target:LogTarget = getTargetInstance(targetType);
			if (target == null)
			{
				// Creates the new tartget instance
				switch(targetType)
				{
					case LogTargetType.TRACE:
					{
						target= new TraceLogTarget(options);
						break;
					}
					case LogTargetType.REMOTE:
					{
						target= new RemoteLogTarget(options);
						break;
					}
					case LogTargetType.TEXTAREA:
					{
						target= new TextAreaLogTarget(options);
						break;
					}
				}
				// Add the LogTarget to the dictionary
				_targets[targetType] = target;
			}
			return target;
		}
		
	}
}